const express = require('express'), app = express();
const request = require("request");
// Add nuxt.js middleware
app.use('/', (req, res, next) => {
    const url = "http://192.168.1.177:8088"+req.url;
    // if(/^\/api\/fileUpload/.test(req.url)){
    //   req.pipe(request(url)).pipe(res.set('Access-Control-Allow-Origin', '*'));
    // }
  if (/^\/shaliang/.test(req.url)) {
      console.log(req.url) 
      try {
        const options = { 
          url,
          method: req.method,
          json: true,
          headers:{
            "content-type":req.headers["content-type"],
          },
          body: req.body};
       request(options).pipe(res.set('Access-Control-Allow-Origin', '*'));
  
      }catch (e) {
        console.log(e)
      }
    } else {
      next();
    }
  });
  
  
  export default app;